package com.example.tests;

import com.example.fw.FolderList;
import org.testng.annotations.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

/**
 * Created with IntelliJ IDEA.
 * User: pshevchenko
 * Date: 01.04.13
 * Time: 11:28
 * To change this template use File | Settings | File Templates.
 */
public class TestFolderCreation extends TestBase{
    @Test
    public void testFolderCreation(){

        FolderList oldFolderNames = applicationManager.getFolderHelper().getFolders();

        String folderName = "New Folder";

        assertThat(applicationManager.getFolderHelper().createFolder(folderName), is(nullValue()));

        FolderList newFolderNames = applicationManager.getFolderHelper().getFolders();

        assertThat(newFolderNames, equalTo(oldFolderNames.withAdded(folderName)));
    }

    @Test
    public void testDifferentFoldersCreation(){

        FolderList oldFolderNames = applicationManager.getFolderHelper().getFolders();

        String folderName1 = "New Folder 1";
        String folderName2 = "New Folder 2";

        assertThat(applicationManager.getFolderHelper().createFolder(folderName1), is(nullValue()));

        FolderList newFolderNames1 = applicationManager.getFolderHelper().getFolders();

        assertThat(newFolderNames1, equalTo(oldFolderNames.withAdded(folderName1)));

        assertThat(applicationManager.getFolderHelper().createFolder(folderName2), is(nullValue()));

        FolderList newFolderNames2 = applicationManager.getFolderHelper().getFolders();

        assertThat(newFolderNames2, equalTo(newFolderNames1.withAdded(folderName2)));
    }

    @Test
    public void testDuplicateFoldersCreation(){

        FolderList oldFolderNames = applicationManager.getFolderHelper().getFolders();

        String folderName = "New Duplicate Folder";

        assertThat(applicationManager.getFolderHelper().createFolder(folderName), is(nullValue()));

        FolderList newFolderNames1 = applicationManager.getFolderHelper().getFolders();

        assertThat(newFolderNames1, equalTo(oldFolderNames.withAdded(folderName)));

        assertThat(applicationManager.getFolderHelper().createFolder(folderName), containsString("Duplicated folder name"));

        FolderList newFolderNames2 = applicationManager.getFolderHelper().getFolders();

        assertThat(newFolderNames2, equalTo(newFolderNames1));
    }
}
